package com.visikard.asynctask;

import android.os.Handler;
import android.os.Message;

import com.visikard.application.UIMessage;
import com.visikard.business.AudienceBUS;
import com.visikard.response.BaseResponse;
import com.visikard.response.GetListUserRatingResponse;

public class GetListUserRatingTask extends BaseTask {

	public static final int POS_ID_CAMPAIGN_SPECIAL = 0;
	public static final int POS_PAGE_INDEX = 1;
	public static final int POS_PAGE_SIZE = 2;

	public GetListUserRatingTask(Handler handler) {
		super(handler);
	}

	public GetListUserRatingTask(Handler handler, boolean isShowProgress) {
		super(handler, isShowProgress);
	}

	@Override
	protected Object doBackgroundWork(Object... params) {

		// Get params
		String idCampaignSpecial = (String) params[POS_ID_CAMPAIGN_SPECIAL];
		int pageIndex = (Integer) params[POS_PAGE_INDEX];
		int pageSize = (Integer) params[POS_PAGE_SIZE];

		// Validation

		// Call service
		AudienceBUS busObj = new AudienceBUS();
		return busObj.getListUserRating(idCampaignSpecial, pageIndex, pageSize);
	}

	@Override
	protected boolean handleResult(Object result) {
		GetListUserRatingResponse response = (GetListUserRatingResponse) result;
		if (response != null) {
			switch (response.getErrorCode()) {
				case BaseResponse.SUCCESS:
					Message successMsg = new Message();
					successMsg.what = UIMessage.MSG_GET_DATA_SUCCESS;
					successMsg.obj = response.getListItemAudienceKards();
					mUIHandler.sendMessage(successMsg);
					return true;
			}
		}
		return false;
	}

}
